<script>
import { isLoggedIn } from '@/utils/auth.js';

	export default {
		onLaunch: function() {
		console.log('App Launch');
		this.checkUpdate();
		},
		onShow: function() {
		console.log('App Show');
		},
		onHide: function() {
		console.log('App Hide');
	},
	methods: {
		/**
		 * 检查应用更新
		 */
		checkUpdate() {
			// #ifdef APP-PLUS  
			plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
				uni.request({
					url: 'http://localhost:3000/api/mobile/app/version',
					data: {
						version: widgetInfo.version
					},
					success: (result) => {
						const data = result.data;
						if (data.code === 200 && data.data.hasUpdate) {
							// 有新版本
							uni.showModal({
								title: '发现新版本',
								content: data.data.updateContent,
								confirmText: '立即更新',
								success: (res) => {
									if (res.confirm) {
										// 打开下载链接
										plus.runtime.openURL(data.data.downloadUrl);
									}
								}
							});
						}
					}
				});
			});
			// #endif
		}
		}
	}
</script>

<style>
	/*每个页面公共css */
	page {
		font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Segoe UI, Arial, Roboto, 'PingFang SC', 'miui', 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif;
		--primary-color: #7FB992;
		--text-color: #333333;
		--text-color-secondary: #666666;
		--text-color-tertiary: #999999;
		--border-color: #EEEEEE;
		--bg-color: #F8F8F8;
	}

	/* 通用样式 */
	.page-container {
		min-height: 100vh;
		background-color: var(--bg-color);
	}

	.section-title {
		font-size: 32rpx;
		font-weight: bold;
		color: var(--text-color);
		margin-bottom: 20rpx;
	}

	/* 按钮样式 */
	.primary-btn {
		width: 100%;
		height: 90rpx;
		background-color: var(--primary-color);
		color: #FFFFFF;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
	}

	.secondary-btn {
		width: 100%;
		height: 90rpx;
		background-color: #FFFFFF;
		color: var(--primary-color);
		border: 1px solid var(--primary-color);
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
	}
</style>
